function[ppef] = ppefm(IEF, flag)
% Function returns the EEF from 
% Input IEF data. IEF should be a vector of IEF data
% either IEF Ex or Ey. flag should be either "Ez" or "Ey"
% The transfer function assumes that the data interval
% is 5 minutes


	%
		 % Define the transfer function filter coefficients
		 % 
		 % Transfer function between IEF Ey and EEF These are from
		 % /home/mnair/projects/longp/final_coefficients a_n b_n They are the
		 % estimates from JULIA & CHAMP. Derived on 12/09/2008
		 %/
% 
% 		Tx_a = [ 1.0000, -0.6023, -0.6600, 0.4451, -0.0463 ];
% 
% 		Tx_b = [ 0.0052, 0.0151, 0.0014, -0.0152, -0.0061 ];
% 
        % April 4, 2012
        % the data are in /home/mnair/projects/longp/TF_JULIA_CHAMP_final_coefficients
%         
%         Tx_a = [1.0000000000 -1.8629976540 1.1142226084 -0.2291330136];
%                    
%         Tx_b = [0.0107232329  -0.0036079201 -0.0070761662];

%        April 13, 2012. the new coefficients are derived from JULA and
%        CHAMp for ap > 20 days. Also found that E-eff scaling affected ACE
%        spectra
         Tx_a = [ 1.0000000000 -0.5857685663 -0.9552092349 0.6300518820];
         Tx_b = [  0.0179652952 0.0092006195 -0.0177488188 -0.0089805341];

    

% 		%
% 		 % Transfer function between IEF Ey and EEF Note that these coefficients
% 		 % are still under the process of development and will change in the
% 		 % near future Manoj Nair Sep , 2011
% 				
%          
%         Ty_a = [ 1.0000, -1.256299, 0.412882 ];
% 
% 		Ty_b = [ 0.000824, 0.000170, -0.000296, -0.001166 ]; 
        
        
        
        if flag == 'Ey',
            
          ppef =  filter(Tx_b,Tx_a, IEF);
        elseif flag == 'Ez',
            ppef =  filter(Ty_b,Ty_a, IEF);
        else
            display('Error !. the flag should be either "Ez" or "Ey"');
            
            ppef = NaN;
        end;